package jangdolbaeng2.seller.dao;

import jangdolbaeng2.db.MybatisConfig;
import jangdolbaeng2.vo.Shop_noticeVO;

import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;

public class NoticeDAO {
	SqlSessionFactory factory = MybatisConfig.getSqlSessionFactory();
	
	public Shop_noticeVO noticeGet(int shop_seq){		
		SqlSession ss = factory.openSession();
		Shop_noticeVO vo = null;
		
		try{
			vo = ss.selectOne("qa.noticeGet", shop_seq);
			
		}catch(Exception e) {
			e.printStackTrace();
		}
		finally {
			if (ss != null) ss.close();
		}
		return vo;
	}
	
	public void noticeInput(Shop_noticeVO noticeVO){
		SqlSession ss = factory.openSession();
		Shop_noticeVO vo = null;
		try{
			vo = ss.selectOne("qa.noticeGet", noticeVO);
			System.out.println(vo);
			if(vo == null)
				ss.insert("qa.noticeInput", noticeVO);
			else
				ss.update("qa.noticeUpdate", noticeVO);
			
			ss.commit();
		}catch(Exception e){
			e.printStackTrace();
		}
		finally {
			if (ss != null) ss.close();
		}
		return;
	}
	
	public void noticeUpdate(Shop_noticeVO noticeVO){
		SqlSession ss = factory.openSession();
		try {
			ss.update("qa.noticeUpdate", noticeVO);
			ss.commit();
		} catch (Exception e) {
			e.printStackTrace();
		}
		finally {
			if (ss != null) ss.close();
		}
		return;
	}
	
	public void noticeDel(int shop_seq){
		SqlSession ss = factory.openSession();
		try {
			ss.delete("qa.noticeDel", shop_seq);
			ss.commit();
		} catch (Exception e) {
			e.printStackTrace();
		}
		finally {
			if (ss != null) ss.close();
		}
		return;
	}
}
